package rsvp;

import java.io.IOException;

import org.junit.Test;

/**
 * Testing the main RSVP component
 * 
 * @author ksz
 *
 */
public class Test_AllOK
{
	private String m_sTestName = null;	
	protected final Main_RSVP applet = new Main_RSVP();
	
	/**
	 * @param sTestName
	 */
	public void before(String sTestName) {
		
		// TODO JUnit how to obtain test name
		m_sTestName = sTestName;
		System.out.println("------------sTestName = " + m_sTestName);
		applet.loadMain("./test/rsvp.Test_RSVP/51879_o.txt");
		logInTitle(applet, "File loaded");
		
		applet.doStop_ifStarted();
		logInTitle(applet, "stopped");			
	}
	
	/**
	 * @throws InterruptedException
	 */
	public void after() throws InterruptedException {
		System.out.println("after called");
		applet.doStop_ifStarted();
		applet.win.setVisible(false);
		applet.win.dispose();
		applet.destroy();	
		
//		// wait until thread is stopped
//		applet.thread.join();
//		Thread.sleep(100);
	}
	
	/**
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@Test public void testPaqeDown() throws IOException, InterruptedException {
		before("testPaqeDown()");
		System.out.println("testPaqeDown called");
		
		
		for (int i = 0; i < 10; i++)
		{
			applet.controlBigDisplay.callPageDown();
			logInTitle(applet, "page down called (" + i + ")");
			//Thread.sleep(1 * 100);
		}
		after();
	}
	
	/**
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@Test public void testReadWholeText() throws IOException, InterruptedException {
		before("testReadWholeText()");

		// TODO set high speed
		applet.doStart_ifStopped();
		logInTitle(applet, "StartReading");			
		
		// wait until thread is stopped
		applet.thread.join();
		after();
	}

	/**
	 * Log which stage of the test is running now
	 * 
	 * @param applet
	 * @param sStage
	 */
	private void logInTitle(Main_RSVP applet, String sStage)
	{
		applet.win.setTitle(m_sTestName + " " + sStage);
	}	

}
